How do I get categories for a product in Magento [closed]

Posted by Joost de Valk on Pro Webmasters See other posts from Pro Webmasters or by Joost de Valk
Published on 2011-02-15T20:54:42Z Indexed on 2011/02/15 23:34 UTC
Read the original article Hit count: 274

Filed under:
|

I'm trying to add product_type to my Magento Google Base output based on the product's categories, but I seem to be unable to. I have the following code:

// Get categories from  product to include as product_type
$categoryIds = $object->getCategoryIds();
foreach($categoryIds as $categoryId) {
    $category = Mage::getModel('catalog/category')->load($categoryId);
    $this->_setAttribute('product_type', $category->getName(), 'text' );
}

The issue is that it returns all of the categories, not just the ones the product is in. Anyone have a solution?

© Pro Webmasters or respective owner

Related posts about php

Related posts about magento